var express = require('express');
var router = express.Router();

var Student = require('../modules/schema.js').Student;
var Teacher = require('../modules/schema.js').Teacher;
var Course = require('../modules/schema.js').Course ;
var Exam = require('../modules/schema.js').Exam;
var Case_info = require('../modules/schema.js').Case_info;
var Learn_info = require('../modules/schema.js').Learn_info;
var Job_info = require('../modules/schema.js').Job_info;


router.get('/student/login',function(req,res){
	res.render('student/login',{});
});

router.post('/student/login',function(req,res){
	Student.findOne({sid:req.body.sid},{name:1,sid:1,_id:0,Course:1}).exec(function(err,student){
		if(err) console.log(err);
		if(req.body.name == student.name){
			req.session.user = student;
			return res.redirect('/student');
		}
	});
});

router.get('/student', function(req, res) {
	res.render('student',{user = req.session.user});
});

router.get('/student/course_table',function(req,res){
	var cids = [];
	for(var i in req.session.user.Course){
		cid.push(req.session.user.Course[i].cid);
	}
	Course.find({cid:{"$in":cids}}).exec(function(err,courses){
		if(err) console.log(err);
		res.render('student/course_table',{courses:courses,user:req.session.user});
	});
});





module.exports = router;
